<script src="/misc/js/order.js"></script>
<link rel="stylesheet" href="/v2/css/member.css?12345">
<header class="header">
    <div class="fix_nav">
        <div class="nav_inner">
            <a class="nav-left back-icon" href="/member/index/index.html">返回</a>
            <div class="tit">我的订单</div>
        </div>
    </div>
</header>
<div class="order_bg_img">
    <div class="order_i_p_c">
        <div class="order_i" <?php if($type == 'all') echo 'id="qb"';?>>
            <a href="/member/order/index.html">
                <div class="order_pic"><img src="/misc/images/order_bg_4.png"></div>
                <div class="order_tit">全部</div>
            </a>
        </div>
    </div>
    <div class="order_i_p_c">
        <div class="order_i" <?php if($type == 'wait') echo 'id="qb"';?>>
            <a href="/member/order/index/type/wait.html">
                <div class="order_pic"><img src="/misc/images/order_bg_3.png"></div>
                <div class="order_tit">待付款</div>
            </a>
            <?php if($total['wait']):?>
            <div class="order_tit_tb_bg"><?=$total['wait']?></div>
            <?php endif;?>
        </div>
    </div>
    <div class="order_i_p_c">
        <div class="order_i" <?php if($type == 'activate') echo 'id="qb"';?>>
            <a href="/member/order/index/type/activate.html">
                <div class="order_pic"><img src="/misc/images/order_bg_1.png"></div>
                <div class="order_tit">待激活</div>
            </a>
            <?php if($total['activate']):?>
            <div class="order_tit_tb_bg"><?=$total['activate']?></div>
            <?php endif;?>
        </div>
    </div>
    <div class="order_i_p_c">
        <div class="order_i" <?php if($type == 'comment') echo 'id="qb"';?>>
            <a href="/member/order/index/type/comment.html">
                <div class="order_pic"><img src="/misc/images/order_bg.png"></div>
                <div class="order_tit">待评价</div>
            </a>
            <?php if($total['comment']):?>
            <div class="order_tit_tb_bg"><?=$total['comment']?></div>
            <?php endif;?>
        </div>
    </div>
</div>

<div class="order_content_cou" id="dfk_df">

    <?php foreach($list as $item): ?>
    <div class="order_i_h"></div>
    <div class="order_co_top">
        <div class="order_co_t_l fk">
            <?php if($item['status'] == OrderModel::STATUS_CANCELLED):?>
                <span style="color:red;">订单关闭</span>
            <?php elseif($item['status'] == OrderModel::STATUS_COMPLETED):?>
                <span class="status_complete"><?=OrderModel::$status_text[$item['status']]?></span>
            <?php else:?>
                <span class="status_waitpay"><?=OrderModel::$status_text[$item['status']]?></span>
            <?php endif;?>
        </div>
        <div class="order_co_t_r">
            <a href="/member/order/view/sn/<?=$item['sn']?>.html" title="点击查看订单详情">订单号：<?=$item['sn']?></a>
        </div>
    </div>
    <div class="order_c_pic_tit"  style="border:1px solid #fff">
        <?php foreach($item['products'] as $product): ?>
        <div class="order_c_p_l">
            <a href="/product/detail/goods_id/<?=$product['product_id']?>.html" title="点击查看商品详情">
                <img  src="<?=$product['product_thumb']?>" class="photo">

            </a>
        </div>
        <div class="order_c_p_r">
            <div class="order_c_p_r_t">
                <a href="/member/order/view/sn/<?=$item['sn']?>.html" title="点击查看订单详情">
                <div class="order_c_p_r_tit"><?=$product['product_name']?></div>

                <div class="order_c_p_r_pri">单价：￥ <?=price_format($product['price'])?></div>
                <div class="order_c_p_r_pri">数量：<?=$product['num']?></div>
                </a>
            </div>
        </div>
        <?php endforeach;?>
    </div>
    <div class="order_bot_cou">
        <div class="order_bot_l">
            <div class="order_bot_l_s"><span>订单金额：</span><span class="order_bot_l_m">￥<?=price_format($item['amount'])?></span></div>
        </div>
        <div class="order_bot_r">
            <div class=" fr mobile_operation">
                <?php if($item['status'] == OrderModel::STATUS_WATI_PAY && $item['pay_status'] == OrderModel::PAY_STATUS_NO_PAY):?>
                <span order_sn="<?=$item['sn']?>" class="J_closeOrder btn btn-default" style="margin-right: 10px;">取消订单</span>
                <span order_sn="<?=$item['sn']?>" class="J_payOrder btn btn-warning">去付款</span>
                <?php elseif($item['status'] == OrderModel::STATUS_WATI_ACTIVE):?>
                <span order_sn="<?=$item['sn']?>" class="btn btn-danger share_btn"> 我要分享 </span>
                <span order_sn="<?=$item['sn']?>" class="J_activeOrder btn btn-info">去激活</span>
                <?php elseif($item['status'] != OrderModel::STATUS_CANCELLED):?>
                <span order_sn="<?=$item['sn']?>" class="btn btn-danger share_btn"> 我要分享 </span>
                <?php endif;?>
            </div>
        </div>
    </div>
    <?php endforeach;?>
    <div class="clear"></div>
    <div class="order_i_h">
    </div>
    <?php if(count($list) == 0):?>
        <div class="alert alert-info" role="alert" style="background: #fff; border: none;">
            <?php if($type == 'all'):?>
                您还没有任何购买商品！
            <?php else:?>
                您还没有此类型订单！
            <?php endif;?>
            <a class="btn btn-info" href="/">去购买</a>
        </div>
    <?php endif;?>
    <?php include APP_PATH.'views/common/page.php'?>
</div>

<?php include APP_PATH.'views/common/share.php'?>
<script type="text/javascript">

    var orders = <?php echo json_encode($list);?>;
    var shareData = {
        title: '',
        desc: '我在天天加油购买一款超值的加油卡，不仅可以超值加油，还可以赚钱！',
        link: '',
        imgUrl: '',
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    };

    var shareTimeLineData = {
        title: '我在天天加油购买一款超值的加油卡，不仅可以超值加油，还可以赚钱！',
        link: '',
        imgUrl: '',
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    };

    $(document).ready(function(){
        $(".share_btn").click(function(){
            var order_sn = $(this).attr('order_sn')
            $.each(orders,function(k,order){
                if(order.sn == order_sn){
                    var product = order.products[0];
                    shareData.title = product.product_name;
                    shareData.link = sprintf('<?=DOMAIN.'/product/detail/goods_id/%s.html?cpsid='.$cpsid?>',product.product_id);
                    shareData.imgUrl = product.product_thumb;

                    shareTimeLineData.link = shareData.link;
                    shareTimeLineData.imgUrl = product.product_thumb;
                }
            })
        })
        $('.J_closeOrder').css('margin-right','10px');
    });

    wx.ready(function () {

        wx.onMenuShareAppMessage(shareData);
        wx.onMenuShareTimeline(shareTimeLineData);
        wx.onMenuShareQQ(shareData);
        wx.onMenuShareWeibo(shareData);
    });
    function sprintf()
    {
        var arg = arguments,
            str = arg[0] || '',
            i, n;
        if(arg[1] != null && typeof(arg[1]) == 'object'){

            $.each(arg[1],function(i,v){
                str = str.replace(/%s/, v);
            });

            delete arg[1];
        }
        for (i = 1, n = arg.length; i < n; i++) {
            str = str.replace(/%s/, arg[i]);
        }
        return str;
    }
</script>
